package cn.mumzone.pos.ui.fragment.bills;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;

import com.github.jdsjlzx.recyclerview.LRecyclerView;
import com.github.jdsjlzx.recyclerview.LRecyclerViewAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import cn.mumzone.basic.base.BaseFragment;
import cn.mumzone.basic.util.ToastUtil;
import cn.mumzone.pos.R;
import cn.mumzone.pos.ui.adapter.ADA_BillGoodsDetail;
import cn.mumzone.pos.ui.adapter.ADA_BillServiceDetail;
import cn.mumzone.pos.model.BillConsumeDetailsEntity;
import cn.mumzone.pos.model.BillDetailEntity;

/**
 * Created By Dlx
 * on 2019/6/28
 * 消费详情-商品列表
 */
public class FRA_BillGoodsDetail extends BaseFragment {
    @BindView(R.id.billitem_recyclerview)
    LRecyclerView billItemRecyclerview;
    private List<BillConsumeDetailsEntity.GoodsListBean> goodsList = new ArrayList<>();
    private List<BillConsumeDetailsEntity.ListBean> serviceList = new ArrayList<>();
    private ADA_BillGoodsDetail goodsAdapter;
    private ADA_BillServiceDetail serviceAdapter;
    private LRecyclerViewAdapter lRecyclerViewAdapter = null;
    private int enterType;

    public void setDatas(BillDetailEntity data, int enterType) {
        if (data == null || ((data.getList() == null || data.getList().size() == 0) && (data.getGoodsList() == null || data.getGoodsList().size() == 0))) {
            ToastUtil.debugToast(mContext, "datas is null or list size is 0", false);
            return;
        }
        this.enterType = enterType;
        if (enterType == FRA_BillItem.GOODS || enterType == FRA_BillItem.INTEGRAL_GOODS) {
            goodsList = data.getGoodsList();
            goodsAdapter.setIntegralGoods(enterType == FRA_BillItem.INTEGRAL_GOODS);
            goodsAdapter.setDataList(goodsList);
        } else if (enterType == FRA_BillItem.SERVICE) {
            serviceList = data.getList();
            serviceAdapter.setDataList(serviceList);
        }
    }


    @Override
    protected void onUserVisible() {

    }

    @Override
    protected void initEventAndData() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        billItemRecyclerview.setLayoutManager(layoutManager);
        enterType = getArguments().getInt("enterType", -1);
        goodsAdapter = new ADA_BillGoodsDetail(mContext);
        serviceAdapter = new ADA_BillServiceDetail(mContext);
        goodsAdapter.setDataList(goodsList);
        serviceAdapter.setDataList(serviceList);
        if (enterType == FRA_BillItem.GOODS || enterType == FRA_BillItem.INTEGRAL_GOODS) {
            lRecyclerViewAdapter = new LRecyclerViewAdapter(goodsAdapter);
            billItemRecyclerview.setAdapter(lRecyclerViewAdapter);
        } else if (enterType == FRA_BillItem.SERVICE) {
            lRecyclerViewAdapter = new LRecyclerViewAdapter(serviceAdapter);
            billItemRecyclerview.setAdapter(lRecyclerViewAdapter);
        }
        billItemRecyclerview.setPullRefreshEnabled(false);
        billItemRecyclerview.setLoadMoreEnabled(false);
    }

    @Override
    protected int getLayout() {
        return R.layout.fra_billitem;
    }

    public static FRA_BillGoodsDetail newInstance(int enterType) {
        FRA_BillGoodsDetail fra = new FRA_BillGoodsDetail();
        Bundle bundle = new Bundle();
        bundle.putInt("enterType", enterType);
        fra.setArguments(bundle);
        return fra;
    }

}
